# -*- coding: utf-8 -*-

from clint.textui import prompt, puts, colored, validators
import json
import codecs
from message import *


def select_lang():
    lang_options = [{'selector': '1', 'prompt': '中文', 'return': 'zh'},
                    {'selector': '2', 'prompt': 'English', 'return': 'en'}]
    return prompt.options("请选择交互语言/Please select a language", lang_options)


def get_domain(lang):
    domain = prompt.query(Message["ask_domain"][lang], default='', validators=[])
    return domain


def get_username(lang):
    username = prompt.query(Message["ask_username"][lang])
    return username


def get_password(lang):
    password = prompt.query(Message["ask_password"][lang])
    return password


def get_region(lang):
    if lang == "zh":
        regions_options = [{'selector': '1', 'prompt': '大连', 'return': '东北-大连'},
                           {'selector': '2', 'prompt': '北京-1', 'return': '华北-北京-1'},
                           {'selector': '3', 'prompt': '北京-4', 'return': '华北-北京-4'},
                           {'selector': '4', 'prompt': '上海-2', 'return': '华东-上海-2'},
                           {'selector': '5', 'prompt': '广州', 'return': '华南-广州'}]
    else:
        regions_options = [{'selector': '1', 'prompt': 'Dalian', 'return': '东北-大连'},
                           {'selector': '2', 'prompt': 'Beijing-1',
                               'return': '华北-北京-1'},
                           {'selector': '3', 'prompt': 'Beijing-4',
                               'return': '华北-北京-4'},
                           {'selector': '4', 'prompt': 'Shanghai-2',
                               'return': '华东-上海-2'},
                           {'selector': '5', 'prompt': 'Guangzhou', 'return': '华南-广州'}]
    return prompt.options(Message["ask_region"][lang], regions_options)


def get_task(lang):
    task_options = [{'selector': '0', 'prompt': Message['ask_task_quit'][lang], 'return':'quit'},
                    {'selector': '1', 'prompt': Message['ask_task_backup'][lang], 'return':'backup'},
                    {'selector': '2', 'prompt': Message['ask_task_restore'][lang], 'return':'restore'},
                    {'selector': '3', 'prompt': Message['ask_task_move'][lang], 'return':'move'},
                    {'selector': '4', 'prompt': Message['ask_task_display'][lang], 'return':'display'},
                    {'selector': '5', 'prompt': Message['ask_task_download'][lang], 'return':'download'},
                    {'selector': '6', 'prompt': Message['ask_task_upload'][lang], 'return':'uploadRepos'}]
    return prompt.options(Message["ask_task"][lang], task_options)

def get_file_path(lang):
    file_path = prompt.query(Message["ask_file_path"][lang], default='./config.csv', validators=[validators.FileValidator()])
    return file_path